
public class Solution {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int[] time = new int[releaseTimes.length];
        char[] KeysPressed = keysPressed.toCharArray();
        time[0] = releaseTimes[0];
        for(int i = 1;i < time.length;i ++){
            time[i] = releaseTimes[i] - releaseTimes[i - 1];
        }
        return KeysPressed[FindLongestTime(time,KeysPressed)];
    }
    public int FindLongestTime(int[] time,char[] KeysPressed){
        int max = 0;
        int MaxI = 0;
        for(int i =0;i < time.length;i ++){
            if (max == time[i] && (KeysPressed[MaxI] - '0' )<= (KeysPressed[i] - '0')){
                MaxI = i;
            }else if (max < time[i]){
                max = time[i];
                MaxI = i;
            }
        }
        return MaxI;
    }
}
